package com.digdes.calendar.service.impl;

import com.digdes.calendar.dao.EventParticipantDAO;
import com.digdes.calendar.gwt.client.dto.EventParticipantDTOImpl;
import com.digdes.calendar.model.EventParticipant;
import com.digdes.calendar.service.EventParticipantService;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class EventParticipantServiceImpl implements EventParticipantService {
    private EventParticipantDAO participantDAO;

    public static EventParticipantDTOImpl makeEventParticipantDto(EventParticipant participant) {
        EventParticipantDTOImpl participantDTO = new EventParticipantDTOImpl();
        UserServiceImpl userService = new UserServiceImpl();
        EventServiceImpl eventService = new EventServiceImpl();
        participantDTO.setId(participant.getId());
        participantDTO.setStatus(participant.getStatus());
       // participantDTO.setEvent(eventService.makeEventDto(participant.getEvent()));
        participantDTO.setParticipant(userService.makeUserDto(participant.getParticipant()));

        return participantDTO;
    }

    public static List<EventParticipantDTOImpl> makeEventParticipantDtoSet(List<EventParticipant> participants) {
        List<EventParticipantDTOImpl> participantsDTO = new ArrayList<EventParticipantDTOImpl>();

        for (Object e : participants) {
            EventParticipant participant = (EventParticipant) e;
            participantsDTO.add(makeEventParticipantDto(participant));
        }
        return participantsDTO;
    }

    public static Set<EventParticipantDTOImpl> makeEventParticipantDtoSet(Set<EventParticipant> participants) {
        Set<EventParticipantDTOImpl> participantsDTO = new HashSet<EventParticipantDTOImpl>();

        for (EventParticipant e : participants) {
            participantsDTO.add(makeEventParticipantDto(e));
        }
        return participantsDTO;
    }

    public EventParticipantDAO getParticipantDAO() {
        return participantDAO;
    }

    public void setParticipantDAO(EventParticipantDAO participantDAO) {
        this.participantDAO = participantDAO;
    }
}
